package com.tt.dp.compound;

import com.tt.dp.compound.adapter.GooseAdapter;
import com.tt.dp.compound.component.Flock;
import com.tt.dp.compound.decorator.QuackCounter;
import com.tt.dp.compound.factory.AbstractDuckFactory;
import com.tt.dp.compound.factory.CountingDuckFactory;
import com.tt.dp.compound.model.Goose;
import com.tt.dp.compound.model.Quackable;
import com.tt.dp.compound.observer.Observer;
import com.tt.dp.compound.observer.Quackologist;

public class DuckSimulator {

    public static void main(String[] args) {

        DuckSimulator duckSimulator = new DuckSimulator();

        AbstractDuckFactory countingDuckFactory = new CountingDuckFactory();

        duckSimulator.simulator(countingDuckFactory);
    }

    private void simulator(AbstractDuckFactory duckFactory){

        Quackable redheadDuck = duckFactory.createRedheadDuck();
        Quackable duckCall = duckFactory.createDuckCall();
        Quackable rubberDuck = duckFactory.createRubberDuck();
        Quackable gooseAdapter = new GooseAdapter(new Goose());

        System.out.println("\nDuck Simulator: with composite - Flocks");

        Flock flock = new Flock();

        flock.add(redheadDuck);
        flock.add(duckCall);
        flock.add(rubberDuck);
        flock.add(gooseAdapter);

        Flock flockOfMallards = new Flock();

        Quackable mallardDuck1 = duckFactory.createMallardDuck();
        Quackable mallardDuck2 = duckFactory.createMallardDuck();
        Quackable mallardDuck3 = duckFactory.createMallardDuck();
        Quackable mallardDuck4 = duckFactory.createMallardDuck();

        flockOfMallards.add(mallardDuck1);
        flockOfMallards.add(mallardDuck2);
        flockOfMallards.add(mallardDuck3);
        flockOfMallards.add(mallardDuck4);

        flock.add(flockOfMallards);

        System.out.println("\nDuck Simulator: with Observer");
        Observer quackologist = new Quackologist();
        flock.registerObserver(quackologist);

        System.out.println("\nDuck Simulator: Whole Flock Simulation");
        simulator(flock);

        System.out.println("\nDuck Simulator: Mallard Flock Simulation");
        simulator(flockOfMallards);

        System.out.println("\nThe ducks quacked " + QuackCounter.getQuacks() + " times");

    }

    private void simulator(Quackable quackableDuck){
        quackableDuck.quack();
    }
}
